﻿using System;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Visualization.Functions {

    /// <summary>
    /// Draw a point.
    /// </summary>
    [Function("Line", "Draw a line", "line([0,0], [1,1])", "")]
    public class PointNode : VisualizationContextFuncNode
    {
        public PointNode()
            : base() {
            base.Value = "point";
        }

        public override object Evaluate() {
            int count = Parameters.Count;
            if (Parameters.Count < 1) {
                throw new Exception("usage: point([x1, y1][, title])");
            }

            ListObject lst1 = (ListObject)Parameters[count - 1].Evaluate();

            if (lst1.Count < 2) {
                throw new ArgumentException("Coordinator is wrong.");
            }

            double x = Convert.ToInt32(lst1[1]);
            double y = Convert.ToInt32(lst1[0]);
            Point2D s = new Point2D(x, y);

            Provider.AddPoint(s);

            return string.Empty;
        }
    }
}
